package com.qiaomengapp.serviceImp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qiaomengapp.bean.ProviderGood;
import com.qiaomengapp.dao.ProviderGoodMapper;
import com.qiaomengapp.exception.CustomException;
import com.qiaomengapp.service.IProvideGoodService;

@Service
public class ImpProvideGoodService implements IProvideGoodService{
	@Autowired
	private ProviderGoodMapper providerGoodMapper;
	
	// 显示供应商商品信息
	public List<ProviderGood> select_ProviderGood() throws CustomException{
		List<ProviderGood> list = providerGoodMapper.select_ProviderGood();
		if (list.size() == 0 || list == null) {
			throw new CustomException("显示供应商商品信息失败");
		} else {
			return list;
		}
	}
	// 根据商品介绍模糊查询
	public List<ProviderGood> select_mohu(String goodDesc){
		List<ProviderGood> list = providerGoodMapper.select_mohu(goodDesc);
		
			return list;
	}
	// 按销量排序
	public List<ProviderGood> select_BySaleCount() throws CustomException{
		List<ProviderGood> list = providerGoodMapper.select_BySaleCount();
		if (list.size() == 0 || list == null) {
			throw new CustomException(" 按销量排序失败");
		} else {
			return list;
		}
	}
	//// 显示销售的商品并按佣金排序
	public List<ProviderGood> select_ByCommission() throws CustomException{
		List<ProviderGood> list = providerGoodMapper.select_ByCommission();
		if (list.size() == 0 || list == null) {
			throw new CustomException(" 显示销售的商品并按佣金排序失败");
		} else {
			return list;
		}
	}
	// 显示销售的商品并按售价排序
	public List<ProviderGood> select_ByPrice() throws CustomException{
		List<ProviderGood> list = providerGoodMapper.select_ByPrice();
		if (list.size() == 0 || list == null) {
			throw new CustomException(" 显示销售的商品并按售价排序失败");
		} else {
			return list;
		}
	}
	//库存和销量的加减
	public void update_sumadd(int a,int id) throws CustomException{
		int i = providerGoodMapper.update_sumadd(a, id);
		if (i == 1) {
			return ;
		} else {
			throw new CustomException("增加库存失败");
		}
	}
	public void update_sumreduce(int a,int id) throws CustomException{
		int i = providerGoodMapper.update_sumreduce(a, id);
		if (i == 1) {
			return ;
		} else {
			throw new CustomException("减少库存失败");
		}
	}
	public void update_salecount_add(int a,int id) throws CustomException{
		int i = providerGoodMapper.update_salecount_add(a, id);
		if (i == 1) {
			return ;
		} else {
			throw new CustomException("增加销量失败");
		}
	}
	public void update_salecount_reduce(int a,int id) throws CustomException{
		int i = providerGoodMapper.update_salecount_reduce(a, id);
		if (i == 1) {
			return ;
		} else {
			throw new CustomException("减少销量失败");
		}
	}
	
	//根据id选出相应的商品信息
	public ProviderGood select_ProviderGoodbyId(int id) throws CustomException{
		ProviderGood providerGood = providerGoodMapper.select_ProviderGoodbyId(id);
		if(providerGood==null){
			throw new CustomException("根据id选出相应的商品信息失败");
		}else{
			return providerGood;
		}
	}
}
